﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace VirtualBlocks
{
    public class QuadRenderer
    {

        #region FieldsAndProperties

        private VertexPositionNormalTexture[] vertices = null;
        private short[] indexBuffer = null;
        private GraphicsDevice device;

        #endregion

        public QuadRenderer(GraphicsDevice device)
        {
            this.device = device;
            vertices = new VertexPositionNormalTexture[]
        {
            new VertexPositionNormalTexture(new Vector3(0,0,0),Vector3.Zero,new Vector2(1,1)),
            new VertexPositionNormalTexture(new Vector3(0,0,0),Vector3.Zero,new Vector2(0,1)),
            new VertexPositionNormalTexture(new Vector3(0,0,0),Vector3.Zero,new Vector2(0,0)),
            new VertexPositionNormalTexture(new Vector3(0,0,0),Vector3.Zero,new Vector2(1,0))
        };

            indexBuffer = new short[] { 0, 1, 2, 2, 3, 0 };
        }

        public void Draw(Vector2 v1, Vector2 v2)
        {
            vertices[0].Position.X = v2.X;
            vertices[0].Position.Y = v1.Y;
 
            vertices[1].Position.X = v1.X;
            vertices[1].Position.Y = v1.Y;
 
            vertices[2].Position.X = v1.X;
            vertices[2].Position.Y = v2.Y;
 
            vertices[3].Position.X = v2.X;
            vertices[3].Position.Y = v2.Y;

            device.DrawUserIndexedPrimitives<VertexPositionNormalTexture>(PrimitiveType.TriangleList, vertices, 0, 4, indexBuffer, 0, 2);
        }

        public void DrawFullScreenQuad()
        {
            Draw(Vector2.One * -1, Vector2.One);
        }

    }
}
